import pygame
from settings import *
from Athlete import *
from Ball import *
from function import *
from Button import *
from game_stats import *
from ShowScore import *

def gaming():
    clock = pygame.time.Clock()
    ai_settings = settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height)
    )
    # # 创建开始游戏按钮
    # play_button = Button(ai_settings, screen, "IceHocket_Game!!!", (255, 0, 255))

    # 实例化游戏状态

    stats = GameStats(ai_settings)
    # buttons = creatButtons(ai_settings, screen,stats)
    ball = Ball(screen, ai_settings)
    athlete_list = createAthlete(screen, ai_settings, stats)
    flag = False
    pygame.display.set_caption("TestGame")

    # 第一视角为蓝色中锋
    current_control = check_currentControl(ai_settings, athlete_list)
    buttons = creatButtons(ai_settings, screen, stats)
    while not stats.stop:
        # stats2 = GameStats(ai_settings)
        showscore = ScoreBoard(ai_settings, screen, stats)
        athlete_list2 = check_eventes(screen, ai_settings, stats, ball, current_control, buttons, athlete_list)
        # if not stats.suspend:
        # if athlete_list2 != None:
        #     current_control = update_screen(screen, ai_settings, stats, ball, athlete_list2, buttons, showscore,
        #                                     current_control)
        # else:
        #     current_control = update_screen(screen, ai_settings, stats, ball, athlete_list, buttons, showscore,
        #                                     current_control)

        if flag == False:
            athlete_list = createAthlete(screen, ai_settings, stats)
            flag = True
        tmp = update_screen(screen, ai_settings, stats, ball, athlete_list, buttons, showscore, current_control)
        if tmp != None:
            current_control = tmp

        # pygame.mouse.set_visible(True)

        # 通过帧率延迟
        clock.tick(100)

def run():
    pygame.init()
    while True:
        gaming()


if __name__=="__main__":
    run()
